package com.haixee.parkdemo.auth.controller;


import com.haixee.parkdemo.auth.entity.dto.AdminLoginDTO;
import com.haixee.parkdemo.auth.entity.request.AdminRequest;
import com.haixee.parkdemo.auth.service.AdminService;
import com.haixee.parkdemo.common.context.WebContextHolder;
import com.haixee.parkdemo.common.response.ResResult;
import com.haixee.parkdemo.common.response.ResUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    @PostMapping("/login")
    public ResResult login(@RequestBody AdminRequest request) {

        AdminLoginDTO data = adminService.getAdminLogin(request.getUsername(), request.getPassword());

        return ResUtil.success(data);
    }

    @PostMapping("/checkout")
    public ResResult checkout(@RequestBody AdminRequest request) {

        AdminLoginDTO data = adminService.checkout(WebContextHolder.getUid(), request.getRoleId());

        return ResUtil.success(data);
    }
}
